package com.ruoyi.project.bajiaostar.tUserAddress.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.bajiaostar.tUserAddress.domain.TUserAddress;
import com.ruoyi.project.bajiaostar.tUserAddress.service.ITUserAddressService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户收货地址Controller
 * 
 * @author wangwu
 * @date 2024-03-04
 */
@Controller
@RequestMapping("/bajiaostar/tUserAddress")
public class TUserAddressController extends BaseController
{
    private String prefix = "bajiaostar/tUserAddress";

    @Autowired
    private ITUserAddressService tUserAddressService;

    @RequiresPermissions("bajiaostar:tUserAddress:view")
    @GetMapping()
    public String tUserAddress()
    {
        return prefix + "/tUserAddress";
    }

    /**
     * 查询用户收货地址列表
     */
    @RequiresPermissions("bajiaostar:tUserAddress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TUserAddress tUserAddress)
    {
        startPage();
        List<TUserAddress> list = tUserAddressService.selectTUserAddressList(tUserAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户收货地址列表
     */
   /* @RequiresPermissions("bajiaostar:tUserAddress:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TUserAddress tUserAddress)
    {
        List<TUserAddress> list = tUserAddressService.selectTUserAddressList(tUserAddress);
        ExcelUtil<TUserAddress> util = new ExcelUtil<TUserAddress>(TUserAddress.class);
        return utill.exportExcel(list, "tUserAddress",null);
    }*/

    /**
     * 新增用户收货地址
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户收货地址
     */
    @RequiresPermissions("bajiaostar:tUserAddress:add")
    @Log(title = "用户收货地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TUserAddress tUserAddress)
    {
        return toAjax(tUserAddressService.insertTUserAddress(tUserAddress));
    }

    /**
     * 修改用户收货地址
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TUserAddress tUserAddress = tUserAddressService.selectTUserAddressById(id);
        mmap.put("tUserAddress", tUserAddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户收货地址
     */
    @RequiresPermissions("bajiaostar:tUserAddress:edit")
    @Log(title = "用户收货地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TUserAddress tUserAddress)
    {
        return toAjax(tUserAddressService.updateTUserAddress(tUserAddress));
    }

    /**
     * 删除用户收货地址
     */
    @RequiresPermissions("bajiaostar:tUserAddress:remove")
    @Log(title = "用户收货地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tUserAddressService.deleteTUserAddressByIds(ids));
    }
}
